home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
msdos
/
utils
/
ptwist.exe
/
POVTWIST.C
next >
Wrap
Text File
|
1993-09-04
|
6KB
|
181 lines
/******************************************************************
*
* Program : Povtwist.c
* Purpose : Create twisted objects for the POVRAY raytracer
* Created : 12/05/90
* By : Drew Wells [CIS 73767,1244] originally for DKBtrace
* POV VERS: James P. Hawkins [CIS 76520,3356]
* Files : Povtwist.c
* Compiler: Microsoft C 7.00
* Model : Medium
* Comments: This simple program used to create the floating twisters in
* the image "Not a Trace of Reality" a.k.a. Ntreal.gif.
* It should be compatible with any ANSI C compiler, and is
* easily modifiable to create more complex shapes by adding
* code to change the x and z axis rotation and step.
*
*
* Copyright 1990 Drew Wells
* This copyrighted code is released for non-commercial use only.
* It may not be sold or used a part of a commercial package.
* This code may be modified and distributed provided it is done at no
* cost to the user.
* Please comment and maintain version list if you modify this code.
******************************************************************/
/* Version
* Twister 0.01 12/05/90 DW Created program.
* Twister 1.00 12/26/90 DW Added user input.
* Povtwist 1.00 09/04/93 JPH POVRAY version derived from Twister
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void show_title(void);
void get_parameters(void);
void write_header(char *filename, char *union_name, char *objname);
void write_quadric(char *objname);
void write_piece(char *objname,double xpos, double ypos, double zpos,
double xrot, double yrot, double zrot);
void write_end(char *filename, char *union_name);
void err_exit(char *message);
FILE *outfile;
char object[80],filename[80],union_name[80],workstr[256];
double length, numtwist, ystep, rstep,xrot,yrot,zrot,x,y,z,numdeg;
long numpieces;
main()
{
show_title();
/* Get twister values from user */
get_parameters();
/* Open file for output and write header */
printf("\n\nCreating POV data file %s...\n", filename);
if ((outfile = fopen(filename,"w")) == NULL)
err_exit("Opening file.");
write_header(filename,union_name, object);
/* Create twister and write each piece to file */
for(y=0.0;y<=length;y+=ystep){
write_piece(object,x,y,z,xrot,yrot,zrot);
yrot += rstep;
if(yrot>=360.0)
yrot = yrot - 360.0;
}
/* Write object end and close file */
write_end(filename,union_name);
fclose(outfile);
printf("\nPOV data file %s created.\n", filename);
return(0);
}
void show_title(void)
{
printf("\n\n\n\n");
printf("___________________________________________________________________\n\n");
printf("[ POVTWIST V1.0 ]\n");
printf("This program creates a POVRAY raytracer data file of a twisted object.\n");
printf("See POVTWIST.doc for more details.\n");
printf("- DW 12/26/90, JPH 09/04/93\n");
printf("___________________________________________________________________\n");
}
void get_parameters(void)
{
/* Get twister values from user */
printf("Twister filename? [twist.pov]: ");
gets(workstr);
strcpy(filename,workstr);
printf("Union name? [Macaroni]: ");
gets(workstr);
strcpy(union_name,workstr);
printf("Quadric name? [Part]: ");
gets(workstr);
strcpy(object,workstr);
printf("Length of twister? [20.0]: ");
gets(workstr);
length = _atold(workstr);
printf("Number of pieces for twister? [50]: ");
gets(workstr);
numpieces = atoi(workstr);
printf("Number of many twists? [1.0]: ");
gets(workstr);
numtwist = _atold(workstr);
/* Set up default values */
if(filename[0]=='\0')
strcpy(filename, "twist.pov");
if(union_name[0]=='\0') strcpy(union_name,"Macaroni");
if(object[0]=='\0') strcpy(object,"Part");
if(length==0.0) length = 20.0;
if(numpieces==0) numpieces = 50;
if(numtwist==0.0) numtwist = 1.0;
xrot = yrot = zrot = x = y = z = 0.0;
ystep = length/(double)(numpieces-1);
rstep = (360.0 * numtwist)/(length/ystep);
}
void write_header(char *filename, char *union_name, char *objname)
{
fprintf(outfile,"/* File : %s Union Name : %s */\n", filename, union_name);
fprintf(outfile,"/* This data file created by POVTWIST for the POVRAY ray tracer. */\n");
fprintf(outfile,"/* NOTE: Change quadric '%s' to change the look of '%s' */\n",
objname, union_name);
fprintf(outfile,"/* See TWISTER docs for more details.*/\n\n");
write_quadric(objname);
fprintf(outfile,"\n/* Twister %s Length=%.3lf Number pieces=%ld Number twists=%.3lf */\n",
union_name,length,numpieces,numtwist);
fprintf(outfile,"#declare %s = object { \n union {\n",union_name);
}
void write_quadric(char *objname)
{
/* Write a sample quadric to file for ease of use */
fprintf(outfile,"#declare %s = quadric { Sphere ", objname);
fprintf(outfile,"scale < %.2lf 1.0 1.0 > }\n", length/4.0);
}
void write_piece(char *objname,double xpos, double ypos, double zpos,
double xrot, double yrot, double zrot)
{
char tofile[256];
sprintf(tofile," quadric { %s\n rotate <%.3lf %.3lf %.3lf> translate <%.3lf %.3lf %.3lf>\n }\n",
objname,xrot,yrot,zrot,xpos,ypos,zpos);
if( fputs(tofile,outfile) )
err_exit("Writing string to file.");
}
void write_end(char *filename, char *union_name)
{
fprintf(outfile," }\n texture { color red 0.9 green 0.1 blue 0.1}\n}\n");
fprintf(outfile,"/* End_File : %s End_Union Name : %s */\n",filename,union_name);
}
void err_exit(char *message)
{
puts("\n\nERROR! \a");
puts(message);
puts("- Exiting program\n[Press Any Key]");
getch();
exit(1);
}